﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using L2Sharp.Data;

namespace L2Sharp.Server
{
    public static class Config
    {
	    //--------------------------------------------------
	    // L2Sharp Property File Definitions - Adapted from L2J
	    //--------------------------------------------------
        // TODO: Database alot of these config files!
	    public static string CHARACTER_CONFIG_FILE = "./config/Character.properties";
	    public static string EXTENSIONS_CONFIG_FILE = "./config/extensions.properties";
	    public static string FEATURE_CONFIG_FILE = "./config/Feature.properties";
	    public static string FORTSIEGE_CONFIGURATION_FILE = "./config/fortsiege.properties";
	    public static string GENERAL_CONFIG_FILE = "./config/General.properties";
	    public static string HEXID_FILE = "./config/hexid.txt";
	    public static string ID_CONFIG_FILE = "./config/idfactory.properties";
	    public static string SERVER_VERSION_FILE = "./config/l2j-version.properties";
	    public static string DATAPACK_VERSION_FILE = "./config/l2jdp-version.properties";
	    public static string L2JMOD_CONFIG_FILE = "./config/l2jmods.properties";
	    public static string LOGIN_CONFIGURATION_FILE = "./config/loginserver.properties";
	    public static string NPC_CONFIG_FILE = "./config/NPC.properties";
	    public static string PVP_CONFIG_FILE = "./config/pvp.properties";
	    public static string RATES_CONFIG_FILE = "./config/rates.properties";
	    public static string CONFIGURATION_FILE = "./config/server.properties";
	    public static string IP_CONFIG_FILE = "./config/ipconfig.xml";
	    public static string SIEGE_CONFIGURATION_FILE = "./config/siege.properties";
	    public static string TW_CONFIGURATION_FILE = "./config/territorywar.properties";
	    public static string TELNET_FILE = "./config/telnet.properties";
	    public static string FLOOD_PROTECTOR_FILE = "./config/floodprotector.properties";
	    public static string MMO_CONFIG_FILE = "./config/mmo.properties";
	    public static string OLYMPIAD_CONFIG_FILE = "./config/olympiad.properties";
	    public static string COMMUNITY_CONFIGURATION_FILE = "./config/CommunityServer.properties";
	    public static string GRANDBOSS_CONFIG_FILE = "./config/Grandboss.properties";
	    public static string CHAT_FILTER_FILE = "./config/chatfilter.txt";

        //--------------------------------------------------
        // Server Settings
        //--------------------------------------------------
        public static int PORT_GAME;
        //public static int PORT_LOGIN;
        public static string LOGIN_BIND_ADDRESS;
        public static int LOGIN_TRY_BEFORE_BAN;
        public static int LOGIN_BLOCK_AFTER_BAN;
        public static string GAMESERVER_HOSTNAME;
        public static string DATABASE_DRIVER;
        public static string DATABASE_URL;
        public static string DATABASE_LOGIN;
        public static string DATABASE_PASSWORD;
        public static int DATABASE_MAX_CONNECTIONS;
        public static int DATABASE_MAX_IDLE_TIME;
        public static int MAXIMUM_ONLINE_USERS;
        public static string CNAME_TEMPLATE;
        public static string PET_NAME_TEMPLATE;
        public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
        //public static File DATAPACK_ROOT;
        public static bool ACCEPT_ALTERNATE_ID;
        public static int REQUEST_ID;
        public static bool RESERVE_HOST_ON_LOGIN = false;
        public static bool LOG_LOGIN_CONTROLLER;

        public static int LOGIN_PORT(int ServerID)
        {
                ConfigDB _cfg = new ConfigDB();

                var cfgItem = (from val in _cfg.ConfigItems
                               where (
                                        (val.ServerID == ServerID) &&
                                        (val.Type == "LGN") &&
                                        (val.Item == "ClientListenPort")
                                     )
                                select new {val.Value }).Single();

                return Convert.ToInt32(cfgItem.Value);
        }
    }
}
